package com.itheima.stock.controller;


import com.itheima.stock.common.domain.*;
import com.itheima.stock.pojo.StockBusiness;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.req.PageResult;
import com.itheima.stock.vo.res.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

//定义股票信息 控制器
@RestController
@RequestMapping("/api/quot")
//@CrossOrigin//解决跨域问题
public class StockController {

    @Autowired
    private StockService stockService;


    @GetMapping("/stock/business/all")
    public List<StockBusiness> findStockBusiness() {
        return stockService.findAll();
    }

    //获取最新的国内大盘参数
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfos() {
        return stockService.getInnerMarketInfos();
    }

    //查询最近最近的版块数据信息
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getStockBlockInfo() {
        return stockService.getStockBlockInfo();
    }

    //统计A股 最新交易数据 并按涨幅取前10
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockInfoByIncrease() {
        return stockService.getStockInfoByIncrease();
    }

    //分页查询股票数据
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getStockByPage(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                           @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        return stockService.getStockByPage(page, pageSize);
    }

    //统计T日没分钟 涨停跌停数据
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpdownCount() {
        return stockService.getStockUpdownCount();
    }

    //股票数据导出到Excel中
    @GetMapping("/stock/export")
    public void exportStockInf4Excel(HttpServletResponse response,
                                     @RequestParam(required = false, defaultValue = "1") Integer page,
                                     @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        stockService.exportStockInf4Excel(response, page, pageSize);
    }

    //通过T日和T-1日大盘成交量对比数据
    @GetMapping("/stock/tradevol")
    public R<Map<String, List>> getStockCompareTradeVol() {
        return stockService.getStockCompareTradeVol();
    }

    //统计当前时间下（精确到分钟），股票在各个涨幅区间的数量
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDwonScopeNum() {
        return stockService.getStockUpDwonScopeNum();
    }

    //查询股票分时数据
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenTimeSharing(@RequestParam("code") String stockCode){
        return stockService.getStockScreenTimeSharing(stockCode);
    }

    //查询股票日k线信息
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDayKLine(@RequestParam("code") String stockCode){
        return stockService.getStockScreenDayKLine(stockCode);
    }
}
